#include "utilityPredefine.h"
#include "Camera.h"

Camera::Camera(void)
{
	pos = Vector3::ZERO;
	rot = Quaternion(1.0,0.0,0.0,0.0);
	yaw = 0;
	roll = 0;
	pitch = 0;

	fovy = 60;
	aspect=1;
	zNear = 5;
	zFar = 1000;
}

Camera::~Camera(void)
{
}

void Camera::update(int matrixMode)
{
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(fovy,aspect,5,1000);
	//glOrtho(-50,50,-30,30,5,1000);
	glMatrixMode(matrixMode);
	glLoadIdentity();
	if(matrixMode==GL_TEXTURE){
		glTranslatef(0.5,0.5,0);
		gluPerspective(fovy,aspect,20,1000);
		glRotatef(pitch,-1,0,0);
		glRotatef(yaw,0,-1,0);
		glRotatef(roll,0,0,-1);
		glTranslatef(-pos.x,-pos.y,-pos.z);
		//Vector3 dir = getDirection();
		//Vector3 pos = getPosition();
		//Vector3 center = pos + dir;
		//gluLookAt(pos.x,pos.y,pos.z,center.x,center.y,center.z,0,1,0);
	}
	else {
		Vector3 dir = getDirection();
		Vector3 pos = getPosition();
		Vector3 center = pos + dir;
		gluLookAt(pos.x,pos.y,pos.z,center.x,center.y,center.z,0,1,0);
	}
//#if(1)
//	Vector3 dir = getDirection();
//	Vector3 center = pos + dir;
//	gluLookAt(pos.x,pos.y,pos.z,center.x,center.y,center.z,0,1,0);
//#else
//	glRotatef(pitch,-1,0,0);
//	glRotatef(yaw,0,-1,0);
//	glRotatef(roll,0,0,-1);
//	glTranslatef(-pos.x,-pos.y,-pos.z);
//#endif
}